
cc.Class({
    extends: cc.Component,

    properties: {
        nd_checked:cc.Node,

        ed_username:cc.EditBox,
        ed_password:cc.EditBox,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        if(G.localData.remePwd){
            this.nd_checked.active = true;
            this.ed_username.string = G.localData.username;
            this.ed_password.string = G.localData.password;
        }else{
            this.nd_checked.active = false;
            this.ed_username.string = '';
            this.ed_password.string = '';
        }
    },

    start () {

    },

    btn_loginClicked(){
        let cur_username = this.ed_username.string.trim();
        let cur_password = this.ed_password.string.trim();
        if(!cur_username){
            G.showToast('请输入账号');
            return;
        }
        if(!cur_password){
            G.showToast('请输入密码');
            return;
        }

        let md5Pwd = G.md5(cur_password);
        G.netApi.user_login({
            username:cur_username,
            password:md5Pwd,
        },(err,data)=>{
            if(err){
                G.showToast('请求错误....');
            }else{
                // 判断是否登陆成功.....
                if(data.err){
                    cc.log('登陆失败.....');
                }else{
                    G.localData.username = cur_username;
                    G.localData.password = cur_password;
                    G.saveData();
                    cc.log('登陆成功...准备跳转..');
                    // cc.log('data:',data);
                    G.setAllData(data);
                    G.gameCtrl.naviToAllItem(data);
                }
            }
        })
    },
    btn_remePwdClicked(){
        if(G.localData.remePwd){
            G.localData.remePwd = 0;
        }else{
            G.localData.remePwd = 1;
        }
        G.saveData();
        this.nd_checked.active = !!G.localData.remePwd;
    },
    btn_gotoRegistClicked(){
        G.winMgr.showRegistLayer();
    },

});
